/**
 * Copyright 2018 人人开源 http://www.renren.io
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.hs.srm.admin.modules.sys.controller;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Date;

import org.apache.shiro.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;

import com.hs.srm.base.common.web.CustomDateEditor;
import com.hs.srm.base.common.web.CustomTimestampEditor;
import com.hs.srm.base.modules.sys.entity.SysUserEntity;
import com.hs.srm.common.utils.DozerUtil;

/**
 * Controller公共组件
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2016年11月9日 下午9:42:26
 */
public abstract class AbstractController implements Serializable {
	
	private static final long serialVersionUID = -4733787837834523092L;
	protected Logger logger = LoggerFactory.getLogger(this.getClass());

	protected Long getDeptId() {
		return this.getUser().getDeptId();
	}

	protected SysUserEntity getUser() {
		Object principal = SecurityUtils.getSubject().getPrincipal();
		return DozerUtil.map(principal, SysUserEntity.class);
	}

	protected Long getUserId() {
		return this.getUser().getUserId();
	}

	@InitBinder
	public void initBinder(WebDataBinder binder) {
		binder.registerCustomEditor(Timestamp.class, new CustomTimestampEditor());
		binder.registerCustomEditor(Date.class, new CustomDateEditor());
	}
    
	
}
